﻿using System;
using System.Windows.Forms;
using ApplicationLibrary.DBManager;
using ApplicationLibrary.ExtendedControls;
using Clothes.Sales.Forms;
using ApplicationLibrary;
using Clothes.Sales.ModuleData;


namespace Clothes.Sales.Library
{
    internal class SaleDocCreator : IDocumentDataManager, IDisposable
    {
        private SaleDoc saleDoc = null;

        public SaleDocCreator(string nameSpace)
        {
            saleDoc = (SaleDoc)GlobalInfo.OpenForm(nameSpace, false);
        }

        public bool AddNew()
        {
            return saleDoc.ToolbarEvent(DocumentForm.ToolbarEventKind.New);
        }

        public bool Edit()
        {
            return saleDoc.ToolbarEvent(DocumentForm.ToolbarEventKind.Edit);
        }

        public bool Save()
        {
            return saleDoc.ToolbarEvent(DocumentForm.ToolbarEventKind.Save);
        }

        public bool Delete()
        {
            return saleDoc.ToolbarEvent(DocumentForm.ToolbarEventKind.Delete);
        }

        public bool Find(IRadarParameters key)
        {
            return saleDoc.FindRecord(key);
        }

        public bool Find(SalesType salesType, string code)
        {
            RadarSalesParam param = new RadarSalesParam(salesType, code);
            return Find(param);
        }

        public void SetHeader(DateTime postingdate, int custcode)
        {
            saleDoc.DocDate = postingdate;
            saleDoc.Customer = custcode;
        }

        public void AddRow(int itemid)
        {
            saleDoc.AddNewRow(itemid);
        }


        //public DataGridViewRow GetRow(int t)
        //{
        //    return 1; // saleDoc.GetDataGrid.Rows[t];
        //}

        //public int RowCount
        //{
        //    get { return je.GetDataGrid.Rows.Count; }
        //}

        //public string JeNumber { get { return je.JeNumber; } }
        //public ExtendedDataGridView GetDataGrid { get { return je.GetDataGrid; } }

        //public string SearchFromDocumentNo(string type, string code, string document)
        //{
        //    if (DRJournalForSales.Find(type, code, document))
        //        return DRJournalForSales.GetValue<string>(PL_JournalEntryDetail.JournalNo);

        //    return "";
        //}

        //public string GetMasterTypeByType(MasterTypes type)
        //{
        //    if (DRMasterTypeByType.Find(type))
        //        return DRMasterTypeByType.GetValue<string>(PL_MasterType.Code);

        //    return "";
        //}

        public void Dispose()
        {
            //je.Close();
            //je.Dispose();
            //GC.SuppressFinalize(je);
            //je = null;
        }
    }
}